package zhao.exmaple;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.connector.file.src.FileSource;
import org.apache.flink.connector.file.src.reader.TextLineFormat;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.LocalStreamEnvironment;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 读取source
 */
public class FileSourceDemo {

    public static void main(String[] args) throws Exception {
        LocalStreamEnvironment env = StreamExecutionEnvironment.createLocalEnvironment();
        // 参数为接口  意味着需要传入接口 实现类，ctrl+H查找实现类也有可能是接口内部的静态方法new一个实现类

        TextLineFormat textLineFormat = new TextLineFormat();
        Path path = new Path("E:\\note\\flink-project\\temp\\word.txt");
        FileSource<String> source = FileSource.forRecordStreamFormat(textLineFormat, path).build();

        DataStreamSource<String> dataSource = env.fromSource(source, WatermarkStrategy.noWatermarks(), "filesourcdemo");

        dataSource.print();

        env.execute();

    }
}
